<?php

namespace Modules\Slider\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Modules\Slider\Entities\Slider;
use Modules\Slider\Http\Requests\SliderRequest;

class SliderController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function index()
    {
    	$data=Slider::paginate(10);
        return view('slider::slider.index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     * @return Response
     */
    public function create(Slider $slider)
    {
        return view('slider::slider.create',compact('slider'));
    }

    /**
     * Store a newly created resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function store(SliderRequest $request)
    {
    	Slider::create($request->all());
    	flash('添加成功！')->overlay ();
    	return redirect ('/slider/slider');
    }

    /**
     * Show the specified resource.
     * @return Response
     */
    public function show()
    {
        return view('slider::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @return Response
     */
    public function edit(Slider $slider)
    {

        return view('slider::slider.edit',compact('slider'));
    }

    /**
     * Update the specified resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function update(SliderRequest $request,$id)
    {
    	$slider=Slider::find($id);
		$slider->title=$request->input('title');
		$slider->link=$request->input('link');
		$slider->thumb=$request->input('thumb');
		$slider->isshow=$request->input('isshow');
		$slider->save();
    	flash('修改成功！')->overlay ();
    	return redirect ('/slider/slider');
    }

    /**
     * Remove the specified resource from storage.
     * @return Response
     */
    public function destroy($id)
    {
    	Slider::destroy ($id);
    	flash('删除成功！')->overlay ();
    	return redirect ('/slider/slider');
    }
}
